package com.spzx.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.dto.IndexHotData;
import com.spzx.product.api.domain.dto.ProductSkuDTO;
import com.spzx.product.api.domain.dto.SkuSearchDTO;
import com.spzx.product.service.ProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sku")
@Tag(name = "商品SKU管理模块")
public class ProductSkuController extends BaseController {

    @Resource
    private ProductSkuService productSkuService;

    @Operation(summary = "内部调用接口：查询首页热门数据")
    @GetMapping("indexHotData")
    //使用R后  远程调用可以自动将查询的结果转为泛型类型
    public R<IndexHotData> indexHotData(){
       IndexHotData hotData = productSkuService.getIndexHotData();
       return R.ok(hotData);
    }

    @Operation(summary = "内部调用接口：查询商品分页列表")
    @GetMapping("list")
    //使用R后  远程调用可以自动将查询的结果转为泛型类型
    public R<Page<ProductSku>> list(SkuSearchDTO skuSearchDTO){
       Page<ProductSku> productSkuPage=productSkuService.listSkus(skuSearchDTO);
       return R.ok(productSkuPage);
    }

    @Operation(summary = "内部调用接口：查询sku详情数据")
    @GetMapping("getSkuDTOById/{id}")
    public R<ProductSkuDTO> getSkuDTOById(@PathVariable("id") Long id){
        ProductSkuDTO productSkuDTO = productSkuService.getSkuDTOById(id);
        return R.ok(productSkuDTO);
    }

}
